<template>
  <div class="app-container">
    <!-- 农场主档案管理表-管理按钮 -->
    <div class="search-bar">
      <el-input v-model="searchData.nczbh" placeholder="请输入农场主编号查询" />
      <el-input v-model="searchData.nczxm" placeholder="请输入农场主姓名查询" />

      <el-button
        v-waves
        type="primary"
        size="small"
        icon="el-icon-search"
        @click="searchBtnHandle"
        >查询</el-button
      >
      <el-button
        v-waves
        type="info"
        size="small"
        icon="el-icon-refresh"
        @click="resetTableList"
        >显示全部</el-button
      >
      <div style="float: right">
        <el-button
          v-waves
          type="primary"
          icon="el-icon-plus"
          @click="openAdd"
          size="small"
          v-permission="'jtnc-nczdagl-krNczdagl-add'"
          >添加农场主档案
        </el-button>
      </div>
    </div>
    <!-- 农场主档案管理表-列表 -->
    <el-table
      ref="dataTable"
      :data="tableData"
      stripe
      border
      @selection-change="handleTableSelectChange"
      v-loading="isLoading"
    >
      <el-table-column
        type="selection"
        width="50"
        align="center"
        header-align="center"
      />
      <el-table-column label="农场主编号" prop="nczbh" align="center" />
      <el-table-column label="农场主姓名" prop="nczxm" align="center" />
      <el-table-column label="性别" prop="nczxb" align="center" />
      <el-table-column label="年龄(岁)" prop="ncznl" align="center" />
      <el-table-column label="联系方式" prop="nczlxfs" align="center" />
      <el-table-column label="家庭住址" prop="nczjtzz" align="center" />
      <el-table-column label="紧急联系人" prop="jjlxr" align="center" />
      <el-table-column label="紧急联系方式" prop="jjlxfs" align="center" />
      <el-table-column fixed="right" label="操作" width="120" align="center">
        <template v-slot="scope">
          <el-button
            type="text"
            style="color: #13ce66"
            size="small"
            @click="openView(scope.row)"
            >详情</el-button
          >
          <el-button
            v-permission="'jtnc-nczdagl-krNczdagl-update'"
            type="text"
            size="small"
            @click="openUpdate(scope.row)"
            >修改
          </el-button>
          <!-- <el-button
            v-permission="'jtnc-nczdagl-krNczdagl-delete'"
            style="color: #ff6d6d"
            type="text"
            size="small"
            @click="deleteByIds(scope.row)"
            >删除
          </el-button> -->
        </template>
      </el-table-column>
    </el-table>
    <!-- 农场主档案管理表-分页 -->
    <el-pagination
      style="text-align: center; margin-top: 10px"
      layout="total,prev,pager,next,sizes,jumper"
      :page-size="pager.limit"
      :current-page="pager.page"
      :total="pager.totalCount"
      @current-change="handleCurrentChange"
      @size-change="handleSizeChange"
    />
    <!-- 添加修改弹窗 -->
    <el-dialog
      :title="titleMap[dialogType]"
      :close-on-click-modal="dialogType !== 'view' ? false : true"
      :visible.sync="dialogFormVisible"
      @close="resetTemp"
      width="600px"
      :key="'myDialog' + dialogIndex"
    >
      <el-form
        ref="dataForm"
        :model="temp"
        label-position="right"
        label-width="110px"
        :disabled="dialogType === 'view'"
      >
        <el-form-item
          label="农场主编号"
          prop="nczbh"
          :rules="[]"
          v-if="dialogType != 'add'"
        >
          <el-input
            v-model="temp.nczbh"
            placeholder="请输入农场主编号"
            :disabled="true"
          />
        </el-form-item>
        <el-form-item
          label="农场主姓名"
          prop="nczxm"
          :rules="[
            { required: true, message: '请输入农场主姓名', trigger: 'blur' },
          ]"
        >
          <el-input v-model="temp.nczxm" placeholder="请输入农场主姓名" />
        </el-form-item>
        <el-form-item
          label="农场主性别"
          prop="nczxb"
          :rules="[
            { required: true, message: '请选择农场主性别', trigger: 'blur' },
          ]"
        >
          <el-select v-model="temp.nczxb" placeholder="请选择农场主性别">
            <el-option label="男" value="男"></el-option>
            <el-option label="女" value="女"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item
          label="农场主年龄"
          prop="ncznl"
          :rules="[
            { required: true, message: '请输入农场主年龄', trigger: 'blur' },
          ]"
        >
          <el-input v-model="temp.ncznl" placeholder="请输入农场主年龄">
            <template #append>岁</template>
          </el-input>
        </el-form-item>
        <el-form-item
          label="农场主联系方式"
          prop="nczlxfs"
          :rules="[
            {
              required: true,
              message: '请输入农场主联系方式',
              trigger: 'blur',
            },
            {
              pattern: /^1[3456789]\d{9}$/,
              message: '请输入正确的手机号',
              trigger: 'blur',
            },
          ]"
        >
          <el-input v-model="temp.nczlxfs" placeholder="请输入农场主联系方式" />
        </el-form-item>
        <el-form-item
          label="农场主家庭住址"
          prop="nczjtzz"
          :rules="[
            {
              required: true,
              message: '请输入农场主家庭住址',
              trigger: 'blur',
            },
          ]"
        >
          <el-input
            v-model="temp.nczjtzz"
            type="textarea"
            maxlength="255"
            placeholder="请输入农场主家庭住址"
          />
        </el-form-item>
        <el-form-item
          label="紧急联系人"
          prop="jjlxr"
          :rules="[
            { required: true, message: '请输入紧急联系人', trigger: 'blur' },
          ]"
        >
          <el-input v-model="temp.jjlxr" placeholder="请输入紧急联系人" />
        </el-form-item>
        <el-form-item
          label="紧急联系方式"
          prop="jjlxfs"
          :rules="[
            { required: true, message: '请输入紧急联系方式', trigger: 'blur' },
            {
              pattern: /^1[3456789]\d{9}$/,
              message: '请输入正确的手机号',
              trigger: 'blur',
            },
          ]"
        >
          <el-input v-model="temp.jjlxfs" placeholder="请输入紧急联系方式" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button
          v-waves
          type="primary"
          v-if="dialogType !== 'view'"
          @click="saveData"
          >保存</el-button
        >
        <el-button v-waves @click="dialogFormVisible = false">取消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import waves from "@/directive/waves";
import crudMixin from "@/mixin/crudMixin";

export default {
  directives: { waves },
  mixins: [crudMixin],
  data() {
    return {
      url: {
        list: "/jtnc/nczdagl/krNczdagl/list",
        add: "/jtnc/nczdagl/krNczdagl/add",
        info: "/jtnc/nczdagl/krNczdagl/getById",
        update: "/jtnc/nczdagl/krNczdagl/update",
        delete: "/jtnc/nczdagl/krNczdagl/delete",
        export: "/jtnc/nczdagl/krNczdagl/export/excel",
      },
      idName: "nczId",
    };
  },
  created() {
    this.loadTableList();
    this.resetTemp();
  },
  methods: {},
};
</script>
<style lang="scss" scoped>
.search-bar {
  margin-bottom: 10px;
  ::v-deep {
    .el-input,
    .el-select {
      width: 180px;
      margin-right: 10px;
      margin-bottom: 5px;
    }
  }
}
</style>
